Skip to content

feat(datepicker): add year selection mode #8565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 12, 2018

Conversation

mmalerba
Copy link
Contributor

@mmalerba mmalerba commented Nov 20, 2017

fixes #5845

@mmalerba mmalerba added this to the 5.1 milestone Nov 20, 2017
@mmalerba mmalerba requested a review from jelbourn November 20, 2017 22:38
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 20, 2017
this._dateAdapter.createDate(curYear - curYear % 24, 0, 1));
let lastYear = this._dateAdapter.getYearName(
this._dateAdapter.createDate(curYear + yearsPerPage - 1 - curYear % 24, 0, 1));
return `${firstYear} \u2013 ${lastYear}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this need to be internationalized?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably should be. I don't think any of our *Intl objects currently have placeholders, so we'd have to make up some convention for that.

Should we switch to using the official Angular i18n stuff? It seems weird that we're just rolling our own.

if (this._currentView == 'year') {
return this._dateAdapter.getYearName(this._activeDate);
}
let curYear = this._dateAdapter.getYear(this._activeDate);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

let curYear = this._dateAdapter.getYear(this._activeDate);
let firstYear = this._dateAdapter.getYearName(
this._dateAdapter.createDate(curYear - curYear % 24, 0, 1));
let lastYear = this._dateAdapter.getYearName(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about selectedYear, firstYearInView and lastYearInView?

@@ -208,29 +230,37 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
this._userSelection.emit();
}

/** Handles month selection in the multi-year view. */
_yearSelected(year: D): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_selectYear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I combined this with _monthSelected and named the new method _goToDateInView

}

/** Handles user clicks on the previous button. */
_previousClicked(): void {
this._activeDate = this._monthView ?
this._activeDate = this._currentView == 'month' ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a _isMonthView() function instead of repeating the comparison?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we gain anything from the method? seems equally readable to what I'm doing here

if (this._currentView == 'year') {
return this._dateAdapter.getYear(date1) == this._dateAdapter.getYear(date2);
}
return Math.floor(this._dateAdapter.getYear(date1) / yearsPerPage) ==
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment like?

// Multi-year view

<tr><th class="mat-calendar-table-header-divider" colspan="4"></th></tr>
</thead>
<tbody mat-calendar-body
role="grid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this also needs aria-readonly="true" since role="grid" treats it as editable by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, moved both of these to mat-calendar-body since they're the same for all of these views

@Misiu
Copy link

Misiu commented Dec 5, 2017

@mmalerba this looks fine.
I'd like to ask for single fix.
When You specify min and max date in calendar view all invalid dates are gray'ed out:
snap 2017-12-05 at 09 35 13

but when You switch to Year view this isn't happening:
snap 2017-12-05 at 09 35 27

Maybe same rule could be applied? Even better would be to hide years that aren't available to pick from (if I have min and max in same Year switching to Year view should be disabled)

@mmalerba
Copy link
Contributor Author

mmalerba commented Dec 7, 2017

@Misiu yeah I should do that, I want to make a separate PR first that changes the way some of the logic works behind the scenes for that feature, then I'll add it here

@Misiu
Copy link

Misiu commented Dec 7, 2017

@mmalerba I've noticed that with latest changes I can't navigate to year list in demo in first comment (https://mmalerba-demo1.firebaseapp.com/datepicker) is this intended?

@mmalerba
Copy link
Contributor Author

mmalerba commented Dec 7, 2017

oh I reused that demo for something else, there's currently no demo for this PR

@Misiu
Copy link

Misiu commented Dec 7, 2017

@mmalerba no worries :) I'll wait till it get merged.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, add merge-ready when ready

expect(calendarInstance._monthView).toBe(false);
expect(calendarInstance._currentView).toBe('multi-year');

(<HTMLElement>calendarBodyEl.querySelector('.mat-calendar-body-active')).click();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use as HTMLElement (here and elsewhere)

@jelbourn jelbourn added pr: lgtm target: minor This PR is targeted for the next minor release and removed pr: needs review labels Dec 7, 2017
@Toub
Copy link

Toub commented Jan 8, 2018

Good job guys!

What is missing in this PR in order to be merged?

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Jan 8, 2018
@andrewseguin andrewseguin merged commit cdbabf7 into angular:master Jan 12, 2018
@mmalerba mmalerba deleted the dp-years branch July 31, 2018 21:56
@FergusZhou
Copy link

@Misiu it seems that what you mentioned (if I have min and max in same Year switching to Year view should be disabled) is not implemented in current version. Do you have any idea about this? Sorry that can't find help with it..

@Misiu
Copy link

Misiu commented Sep 10, 2018

@FergusZhou I'm not using Angular currently. Maybe @mmalerba can help You with this.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make year selectable in date picker
7 participants